package com.java.compilation;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class JackCompiler {

    private List<File> jackFiles = new ArrayList<>();

    public JackCompiler(File... files) {
        Arrays.stream(files).forEach(jackFiles::add);
    }

    public void compile() throws IOException {

        for (File jackFile : jackFiles) {
            JackTokenizer jackTokenizer = new JackTokenizer(jackFile);
            VMWriter vmWriter = new VMWriter(createVMFile(jackFile));
            new CompilationEngine_11(jackTokenizer, new SymbolTable(), vmWriter);
        }
    }

    private static File createVMFile(File jackFile) {
        String vmFile = jackFile.getName().replace("jack", "vm");
        return jackFile.toPath().resolveSibling(vmFile).toFile();
    }

}
